import request from '@/utils/request'
import { genParam } from '@/utils/encrypt'

export function getList(params) {
  genParam(params)

  return request({
    url: '/admin/ad/list',
    method: 'get',
    params
  })
}

export function createAd(param) {
  // console.log(param)
  const paramStr = genParam(param)
  // console.log(paramStr)

  return request({
    url: '/admin/ad/create',
    method: 'post',
    data: paramStr
  })
}

export function editAd(param) {
  const params = {
    name: param.name,
    type: param.type + 1,
    status: param.status,
    past_time: param.past_time,
    ad_addr_type: param.ad_addr_type + 1,
    ad_addr: param.ad_addr,
    ad_one_pop: param.ad_one_pop,
    img: param.img,
    order: param.order
  }
  const paramStr = genParam(params)

  return request({
    url: '/admin/ad/' + param.id + '/edit',
    method: 'put',
    data: paramStr
  })
}

export function deleteAd(param) {
  return request({
    url: '/admin/ad/' + param.id + '/delete',
    method: 'delete'
  })
}
